﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Top.Api;
using Top.Api.Domain;
using Top.Api.Parser;
using Top.Api.Request;
using Top.Api.Response;
using Top.Api.Util;
using DBControl;
using System.Text;

namespace SellerProject
{
    public partial class sellGoodsel : System.Web.UI.Page
    {
        string strGid;
        protected void Page_Load(object sender, EventArgs e)
        {
            strGid = Request.QueryString["binfo"];//获取buyinfo的ID
            //SqlDbHelper sdh = new SqlDbHelper();
            //string strsql = "SELECT ReleaseName,Title,Owner,ExpectpricesMin,ExpectpricesMax FROM BuyersinfoR where Id = '" + strGid + "'";
            //dvBuyerinfo.DataSource = sdh.ExecuteDataTable(strsql);
            //dvBuyerinfo.DataBind();

            //strGid.ToString().Length > 24 ? strGid.ToString().Substring(0, 24) + "..." : strGid.ToString();

            if (Session == null)//盗链处理
            {
                Response.Redirect("sellerLoginChcek.aspx");
            }
            else
            {
                ItopInit iinit = new ItopInit();
                if (!IsPostBack)
                {
                    try
                    {
                        CreateSellCatTree(iinit);//目录树
                    }
                    catch(Exception err)
                    {
                        Response.Redirect("sell404.aspx?errmsg=" + err.Message.ToString());
                    }
                }
            }
        }
        /// <summary>
        /// 取出用户自定义店铺类目并填充Tree
        /// </summary>         
        protected void CreateSellCatTree(ItopInit iinit)
        {
            //ItopInit itop = new ItopInit();
            iinit.sellcatGet(Session["usNick"].ToString());
            List<SellerCat> childlist = new List<SellerCat>();

            StringBuilder sbnode = new StringBuilder();
            sbnode.Append("var zNodes = [");
            for (int i = 0; i < iinit.sclistres.SellerCats.Count; i++)
            {
                if (iinit.sclistres.SellerCats[i].ParentCid == 0) { sbnode.Append("{id:'" + iinit.sclistres.SellerCats[i].Cid.ToString() + "', pId:'0',isParent:true,name:'" + iinit.sclistres.SellerCats[i].Name.ToString() + "'},"); }
                else { sbnode.Append("{id:'" + iinit.sclistres.SellerCats[i].Cid.ToString() + "', pId:'" + iinit.sclistres.SellerCats[i].ParentCid.ToString() + "', name:'" + iinit.sclistres.SellerCats[i].Name.ToString() + "'},"); }
            }
            sbnode.Remove(sbnode.Length - 1, 1);
            sbnode.Append("];");

            StringBuilder sb = new StringBuilder();
            sb.Append("<script language='javascript'>");
            sb.Append(sbnode.ToString());
            sb.Append("$(document).ready(function () { zTree = $('#tree').zTree(setting, zNodes);refushtreenode() });"); //此处写JS代码
            sb.Append("</script>");

            ClientScript.RegisterClientScriptBlock(this.GetType(), "CreateTree", sb.ToString());
        }
       
    }
}